import React, { Component } from 'react'
import axios from 'axios'
import PubSub from 'pubsub-js'

export default class Search extends Component {
    state = {
        users: [], //初始化状态，users初始化值为数据
    }
    search = () => {
        const { keyword: { value } } = this
        axios.get(`https://api.github.com/search/users?q=${value}`).then(
            response => {
                this.props.userData(response.data.items)
                PubSub.publish('guigu', response.data.items)
            },
            error => {
                console.log(error)
            }
        )
    }
    render() {
        return (
            <div className="saerch">
                <input type="text" ref={c => this.keyword = c} />
                <button onClick={this.search}>搜索</button>
            </div>
        )
    }
}